import request from "./request";
import {filterUndefindObj} from '@src/utils/dataHandlingFunc';

// 查询 公司信息
export const getCompanyInfo = async () => {
  const res = await request({
    url: '/company/',
    method: 'get',
    cancelOff: true
  });


  return res;
};

// 创建 公司信息
export const createCompanyInfo = async ({
  company_name,
  company_address,
  scale,
  registered_capital,
  contact_details,
  description,
  company_logo,
  founding_year,
  company_type
}) => {
  const res = await request({
    url: '/company/',
    method: 'post',
    data: filterUndefindObj({
      company_name,
      company_address,
      scale,
      registered_capital,
      contact_details,
      description,
      company_logo,
      founding_year,
      company_type
    })
  });

  return res;
};


// 修改 公司信息
export const editCompanyInfo = async ({
  company_name,
  company_address,
  scale,
  registered_capital,
  contact_details,
  description,
  company_logo,
  founding_year,
  company_type
}) => {
  // const params = filterUndefindObj({
  //   company_name,
  //   company_address,
  //   scale,
  //   registered_capital,
  //   contact_details,
  //   description,
  //   company_logo,
  //   founding_year,
  //   company_type
  // });

  // const formData = new FormData();
  // Object.keys(params).forEach(item => {
  //   formData.append(item, params[item]);
  // });

  const res = await request({
    url: '/company/',
    method: 'put',
    // propsType: 'custom',
    data: {
      company_name,
      company_address,
      scale,
      registered_capital,
      contact_details,
      description,
      company_logo,
      founding_year,
      company_type
    }
  });

  return res;
};

// 修改 公司业务范围
export const editCompanyBusiness = async ({
  business_id
}) => {
  const res = await request({
    url: '/company/business',
    method: 'post',
    propsType: 'custom',
    headers: {
      'Content-Type': 'application/json'
    },
    data: business_id
  });

  return res;
};

// 获取 全部业务范围
export const getAllBusiness = async () => {
  const res = await request({
    url: '/business',
    method: 'get'
  });

  return res;
};

// 修改公司简介
export const editCompanyInfoApi = async ({
  company_profile
}) => {
  const res = await request({
    url: '/company/profile',
    method: 'post',
    data: {
      company_profile
    }
  });

  return res;
};

// 开关 设备供应方
export const switchEquipmentSupplierApi = async ({
  status
}) => {
  const res = await request({
    url: `/company/supplier/${status ? 'enable' : 'disable'}`,
    method: 'put'
  });

  return res;
};

// 获取公司评论
export const getCompanyCommentApi = async ({
  business_server_id
}) => {
  const res = await request({
    url: `/company/business/server/comments?business_server_id=${business_server_id}`,
    method: 'get'
  });

  return res;
};

// 发表评论
export const submitCommentApi = async ({
  business_server_id,
  content,
  parent_id
}) => {
  const res = await request({
    url: '/company/business/server/comments',
    method: 'post',
    data: {
      business_server_id,
      content,
      parent_id
    }
  });

  return res;
};

// 删除评论
export const deleteCommentApi = async ({
  comment_id
}) => {
  const res = await request({
    url: `/company/business/server/comments?comment_id=${comment_id}`,
    method: 'delete'
  });

  return res;
};

// 获取运营商排名
export const getRankList = async () => {
  return await request({
    url: `/company/rankList`,
    method: 'get'
  });
};

